package P116_ExceptionForSelf;

import org.junit.Test;

/**
 * @ClassName : ExceptionForSelf
 * @Description : 异常只为异常服务
 * @Author : wukj1
 * @Date: 2022/5/6
 **/
public class ExceptionForSelf {

    @Test
    public void test(){
        System.out.println(ExceptionForSelf.Contain(test.class, "SPRING1"));
    }

    //判断一个枚举是否包含指定枚举项
    public static <T extends Enum<T>> boolean Contain(Class<T> c,String name){
        boolean result = false;
//        try {
//            Enum.valueOf(c,name);
//            result = true;
//        } catch (RuntimeException e) {
//            //只要抛出异常，则认为是不包含
//        }

        //遍历枚举
        for (T t : c.getEnumConstants()) {
            if(t.name().equals(name)){
                result = true;
            }
        }

        return result;
    }

}

enum test{
    SPRING,SUMMER;
}


